package com.sbs.gaoxinqutoilet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.sbs.gaoxinqutoilet.R;

/**
 * Created by HaiyuKing
 * Used stikcy布局， 可以配置吸顶或者吸底
 */
public class StickyGongGaoAdapter extends DelegateAdapter.Adapter{

	private Context mContext;
	private LayoutHelper mLayoutHelper;
	private String title,more;
	private int mCount = 1;

	public StickyGongGaoAdapter(Context context, LayoutHelper layoutHelper, String title){
		this.mContext = context;
		this.mLayoutHelper = layoutHelper;
		this.title = title;
	}
	public StickyGongGaoAdapter(Context context, LayoutHelper layoutHelper, String title, String more){
		this.mContext = context;
		this.mLayoutHelper = layoutHelper;
		this.title = title;
		this.more = more;
	}

	@Override
	public LayoutHelper onCreateLayoutHelper() {
		return mLayoutHelper;
	}

	@Override
	public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		return new StickyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.vlayout_adapter_item_gonggao, parent, false));
	}

	@Override
	public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
		StickyViewHolder stickyViewHolder = (StickyViewHolder)holder;

		stickyViewHolder.sticky_title.setText(title);

		stickyViewHolder.tv_more.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if(moreClicker!=null){
					moreClicker.callBack("");
				}
			}
		});

	}

	@Override
	public int getItemCount() {
		return mCount;
	}

	static class StickyViewHolder extends RecyclerView.ViewHolder{

		private TextView sticky_title,tv_more;

		public StickyViewHolder(View itemView) {
			super(itemView);
			sticky_title = (TextView) itemView.findViewById(R.id.valyout_sticky_title);
			tv_more = (TextView) itemView.findViewById(R.id.tv_more);
		}
	}

	private MoreClicker moreClicker;

	public interface MoreClicker{
		void callBack(String hotInfoBean);
	}

	public void setMoreClicker(MoreClicker moreClicker) {
		this.moreClicker = moreClicker;
	}
}
